<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogVisible"
    width="50%"
    class="common-dialog"
  >
    <el-table
      :data="tableData"
      style="width: 100%"
      size="small"
      v-loading="loading"
    >
      <el-table-column
        prop="create_time"
        label="创建时间"
      >
      </el-table-column>
      <el-table-column
        prop="username"
        label="司机姓名"
      >
      </el-table-column>
      <el-table-column
        prop="money"
        label="金额">
      </el-table-column>
      <div class="pagination center">
        <el-pagination
          small
          layout="prev, pager, next"
          :page-size.sync="form.size"
          :current-page.sync="form.page"
          :total="total"
          :hide-on-single-page="true"
          @current-change="search"
        >
        </el-pagination>
      </div>
    </el-table>
    <div slot="footer" class="dialog-footer">
      <el-button
        size="small"
        type="primary"
        @click="dialogVisible = false"
      >
        关 闭
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  /**
   * @Author: lifuzhao
   * @Date: 2019-07-29
   * @Project: driver
   */
  import {pageSize} from "../../../constant";

  export default {
    name: "rechargeLog"
    , data() {
      return {
        dialogVisible: false
        , tableData: []
        , form: {
          page: 1
          , size: pageSize
          , d_id: ''
        }
        , total: 0
        , loading: false
        , driver: {}
      }

    }
    , computed: {
      title() {
        let driver = this.driver
        return '正在查看 ' + driver.username + ' 的充值详情'
      }
    }
    , watch: {
      dialogVisible(bool) {
        this.$fn.setTitle(bool ? this.title : '账号管理')
      }
    }
    , mounted() {
      this.init()
    }
    , methods: {
      init() {
        this.$bus.$on('viewAccountRechargeLog', driver => {
          this.driver = driver
          this.form.d_id = driver.id
          this.dialogVisible = true
          this.search(1)
        })
      }
      , search(page) {
        this.form.page = page
        this.getList()
      }
      , getList() {
        this.loading = true
        this.$axios.get('/api/v1/recharges', {
          params: this.form
          , abort: true
        })
          .then(res => {
            let {total = 0, data = []} = res
            this.total = total
            this.tableData = data.map(item => {
              item.username = item.driver && item.driver.username || ''
              return item
            })
          })
          .catch(() => {

          })
          .finally(() => {
            this.loading = false
          })
      }
    }
  }
</script>

<style scoped>

</style>